/**
 * 
 */
package com.globallogic.training.university.people;

import java.util.*;

import com.globallogic.training.university.Strings;

/**
 * Class <code>Person</code> is a parent class of classes <code>Student</code> and <code>Teacher</code>
 * This class represents common features of both classes
 * 
 * @author vasiliy.kulgaviy
 *
 */
public class Person {
	
	private String firstName;
	private String lastName;
	private Date birthDate;
	
	/**
	 * Constructs a person with defined First Name, Last Name and Birth Date
	 * @param firstName the first name of the new person
	 * @param lastName the last name of the new person
	 * @param birthDate the birth date of the new person
	 */
	protected Person(String firstName, String lastName, Date birthDate) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.birthDate = birthDate;
	}

	/**
	 * Returns the first name of the person
	 * @return the first name
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * Returns the last name of the person
	 * @return the last name
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * Returns the birth date of the person
	 * @return the birth date
	 */
	public Date getBirthDate() {
		return birthDate;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object other) {
		if (other == null) return false;
		
		if (this == other) return true;
		
		if (!(other instanceof Person)) return false;
		
		Person otherPerson = (Person) other;
		
		return firstName.equals(otherPerson.getFirstName()) &&
			   lastName.equals(otherPerson.getLastName()) &&
			   birthDate.equals(otherPerson.getBirthDate());
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
        final int prime = 17;
        int result = 37;
        
        result = prime * result + firstName.hashCode();
        result = prime * result + lastName.hashCode();
        result = prime * result + birthDate.hashCode();

		return result;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return String.format(Strings.TO_STRING_PERSON, firstName, lastName);
	}	
}
